package com.sh.personnel.mapper;

import com.sh.personnel.domain.ITbDepartment;
import com.sh.personnel.vo.dto.SelectTreeDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 林思浩
 * @date 2020/03/16 19:29
 */
@Repository
public interface IDeptMapper {

    //获取所有部门信息树
    @Select("SELECT id AS value, name AS label, parentid AS parentId FROM tb_department")
    List<SelectTreeDto> findDepartmentTree();

    //添加部门
    @Insert("INSERT INTO tb_department (name, parentid, createtime)" +
            " VALUES (#{name}, #{parentid}, #{createtime})")
    int insertDepartment(ITbDepartment department);

    //获取部门信息
    @Select("SELECT * FROM tb_department WHERE id = #{id}")
    ITbDepartment findDepartmentById(String id);

    //修改部门信息
    @Update("UPDATE tb_department SET name = #{name}, parentid = #{parentid}, updatetime = #{updatetime}" +
            " WHERE id = #{id}")
    int updateDepartment(ITbDepartment department);

    //删除部门
    @Delete("DELETE FROM tb_department WHERE id = #{id}")
    int deleteDepartmentById(String id);

}
